﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Popup_SuppressList : Popup_Base
{
	const string PARTICIPANT_CELL_NAME = "Cell - Prticipant";
	public GameObject participantCell;
	public UIScrollView participantScrollView;
	public UIGrid participantGrid;

	public GameObject successTitleObject;
	public GameObject failureTitleObject;

	public UILabel bossNameLabel;
	public UILabel finderNameLabel;

	[System.NonSerialized]
	public RaidPartyMember[] selectedRaidPartyMemberList;

	public void LoadPartyMemberList()
	{
		int idx = 0;
		GameObject g = null;

		foreach (RaidPartyMember rpm in selectedRaidPartyMemberList)
		{
			g = NGUITools.AddChild(participantGrid.transform.gameObject, participantCell);
			g.transform.localScale = Vector3.one;
			g.name = PARTICIPANT_CELL_NAME;
			
			ParticipantCell pc = g.GetComponent<ParticipantCell>();
			pc.indexPath = idx;

			pc.nameLabel.text = rpm.name;
			pc.damageLabel.text = string.Format("{0:n0}", rpm.damage);
			pc.raidCountLabel.text = rpm.raidCount.ToString();

			#region - GStar Version
			pc.requestFriendButtonObject.GetComponent<EPButton>().enabled = false;
			pc.writeMessageButtonObject.GetComponent<EPButton>().enabled = false;
			pc.requestFriendButtonObject.SetActive(true);
			pc.writeMessageButtonObject.SetActive(true);

			/*
			if (UserData.Instance.userModel.id == rpm.id)
			{
				pc.requestFriendButtonObject.SetActive(false);
				pc.writeMessageButtonObject.SetActive(false);
			}
			else
			{
				pc.requestFriendButtonObject.SetActive(true);
				pc.writeMessageButtonObject.SetActive(true);
			}
			*/
			#endregion

			idx++;
		}
		participantGrid.Reposition();
		participantScrollView.ResetPosition();
	}

	public override void BackButton ()
	{
		base.BackButton ();
	}

	public void RequestFriendProcess(int selectedIndexPath)
	{
		#region - GStar Version
		return;
		#endregion

		NetworkManager.Instance.C2S_FRIEND_SEND_REQ(selectedRaidPartyMemberList[selectedIndexPath].id, (responseData) => {
			if (responseData.ecode != 0)
			{
				PopupUtility.OneButtonErrorPopupNoBackground(responseData.ecode);
				return;
			}
			
			PopupUtility.OneButtonErrorPopupNoBackground(Localization.Get("uiFriendrequestFriend"));
		});
	}

	public void WriteMessageProcess(int selectedIndexPath)
	{
		#region - GStar Version
		return;
		#endregion

		Popup_WriteMessage pw = PopupManager.PushPopup(PopupKind.WriteMessage) as Popup_WriteMessage;
		pw.receiverId = selectedRaidPartyMemberList[selectedIndexPath].id;
		pw.receiverNameInput.value = selectedRaidPartyMemberList[selectedIndexPath].name;
	}
}